package com.hz.userservice.service.impl;

import com.hz.apiservice.model.dto.TeacherDTO;
import com.hz.userservice.mapper.UserMapper;
import com.hz.userservice.model.entity.UserEntity;
import com.hz.userservice.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Resource
    UserMapper userMapper;
    @Override
    public List<TeacherDTO> allTeachers() {
        List<UserEntity> userEntities = userMapper.getAllTeachers();
        List<TeacherDTO> teacherDTOS = new ArrayList<>();
        userEntities.forEach(userEntity -> {
            TeacherDTO teacherDTO = new TeacherDTO(userEntity.getId(),userEntity.getUsername(),userEntity.getRealname(),userEntity.getStudent_id());
            teacherDTOS.add(teacherDTO);
        });
        return teacherDTOS;
    }
    @Override
    public TeacherDTO findTeacherById(Integer id) {
        UserEntity userEntity = userMapper.findTeacherById(id);
        if (userEntity==null){
            return null;
        }
        TeacherDTO teacherDTO = new TeacherDTO(userEntity.getId(),userEntity.getUsername(),userEntity.getRealname(),userEntity.getStudent_id());

        return teacherDTO;
    }
}
